<template>
  <div class="app-container">
    <div class="ces-main">

      <table>
        <tr>
          <td> <Search-Form class="searchTop" ref="form" size='mini' labelWidth='50px' :searchData='Search'
              :tableCols='tableCols' :searchHandle="searchHandle"></Search-Form></td>
          <td style="width: 300px;"> 
            <v-GetToolBar align="right" :MenuCode="MenuCode" :IsfunEdit='IsfunEdit'
              :Isfunfail='Isfunfail' @handeAdd='handeAdd' @handleEdit='handleEdit' @OpenFindForm='OpenFindForm'
              @handlexportData='handlexportData' @IsfunEdit='handleIsfunEdit' @Isfunfail='handleIsfunfail'
              @IsfunDelete='handleIsfunfail'></v-GetToolBar>
            </td>
        </tr>
      </table>



      <el-form :inline="true" :model="Search" class="demo-form-inline" size="mini">
      </el-form>



      <!-- <ces-table 
            size='mini'
            :isSelection='false'
            :isIndex='true'
            :isSearch='true'
            :isHandle='false'
            :StepSN = '0'
            :IsfunEdit='IsfunEdit'
             :Isfunfail='Isfunfail'
            :tableData='tableData' 
            :tableCols='tableCols' 
            :Search='Search'
            @refresh="refresh"
            @handleEdit='handleEdit'
            @handleDelete='delData'
            >
            </ces-table> -->
      <el-row>

        <el-button size="mini" icon='el-icon-check' @click="handleAllSave">保存</el-button>
        <el-button size="mini" icon="el-icon-delete" @click="delData">删除</el-button>
        <el-button size="mini" icon="el-icon-plus" @click="FunrRowsAdd">增行</el-button>
        <el-button size="mini" icon="el-icon-document-copy" @click="FunCopyRowsAdd">复制</el-button>
        <el-button size="mini" icon="el-icon-document-copy" @click="FunCopyRowsAddOne">复制一行</el-button>
        <el-button size="mini" icon="el-icon-document-copy" @click="RowsAdd">添加数据</el-button>
        <!-- <el-button size="mini" icon="el-icon-document-copy" @click="cancel">test</el-button> -->
      </el-row>

      <ces-table class="cesTable" :ToolBarheight='230' size='mini' :isSelection='false' :isIndex='true' :isSearch='true'
        :isHandle='false' :StepSN='0' :IsfunEdit='IsfunEdit' :Isfunfail='Isfunfail' :tableData='tableData'
        :tableColumns='tableCols' :pagination='Search' @refresh="refresh" @handleEdit='handleEdit'
        @handleDelete='delData' :tableLoading="tableLoading[0]" @workbookInitialized="workbookInitialized"
        @selectChanged="selectChanged" :remark="0" :sysID="0">
      </ces-table>

    </div>

    <!--搜索弹框-->
    <el-dialog title="搜索" :visible.sync="SearchDialog" custom-class="dialogClass" class="searchDialog" center
      ref="searchDialog" :modal="false" :close-on-click-modal="false">
      <el-form :model="Search" label-width="90px" ref="searchForm">



        <Search-Form ref="form" :frame="true" size='mini' labelWidth='50px' :searchData='Search' :tableCols='tableCols'
          :searchHandle="searchHandle"></Search-Form>
      </el-form>

      <div slot="footer" :style="{ 'margin-buttom': 0 == 0 ? DialogBtnMargin : DialogBtnMargin }">
        <el-button @click="reform()">重置</el-button>
        <el-button type="primary" @click="refresh()">确 定</el-button>
      </div>
    </el-dialog>



    <el-dialog v-if="dialogVisible" :visible.sync="dialogVisible" width="800px" top="20px">
      <el-form :model="name" label-width="80px" label-position="right">
        <el-tabs type="border-card">
          <el-tab-pane label="类别管理">
            <el-form :model="FormData" label-width="90px" ref="MianForm">
              <Mian-Form ref="form" :StepSN='0' labelWidth='100px' :FormData='FormData' :tableCols='tableCols'
                :searchHandle="searchHandle"></Mian-Form>
            </el-form>
          </el-tab-pane>
          <div style="float:right ">

            <el-button type="primary" @click="handleOpenClose()">关闭</el-button>
            <el-button type="primary" @click="handleSave()">保存</el-button>

          </div>

        </el-tabs>

      </el-form>

    </el-dialog>


  </div>
</template>

<script>


//引入组件
var _this;
const GCsheets = GC.Spread.Sheets;
import '@grapecity/spread-sheets-vue';
import GC from '@grapecity/spread-sheets';
import '@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css';
import '@grapecity/spread-sheets/js/zh.js';
import { mapState } from 'vuex';
GC.Spread.Common.CultureManager.culture('zh-cn');
import cesTable from "../Common//ComSpreadTable.vue";
import { HeaderCheckBoxCellType } from '@/static/data.js';
//import cesTable from "../Common//table.vue";


import SearchForm from "../Common//Search.vue";
import MianForm from "../Common//form.vue";

import { funDownload, GetTableColsData, SaveData } from "@/api/Common";
import { getDataList, UpdateForm, DeletForm } from '@/api/MesBasic/INDX';
import vGetToolBar from "../Common/GetToolBar";
import a from 'file-saver';
import { forEach } from 'jszip/lib/object';


export default {
  name: "INDX",
  data() {
    //表单查询一般分为input，下拉框，和日期，下面是下拉框时的设置下拉信息的情况，我的项目没有用到，但是留着方便看

    return {
      MenuCode: "A050201",
      tableData: [],//表格数据
      FormData: [],//表格数据
      tableCols: [],//表格列数据
      searchHandle: [],
      StepSN: "0",
      IsfunEdit: false,
      Isfunfail: false,
      Search: {
        // 查询条件
        total: 0, // 总记录数
        pageSize: 20, // 一页显示的记录数
        page: 1, // /当前页码
        RNO: "001", // 表编号  根据Controller中对应的表编号
        jsWhere: "", // 自定义条件

      }, tableLoading: [false, false, false, false],
      spread: [[], [], []],
      selectionData: [[], [], []],
      Indexs: null,
      cities: [
        {
          value: "0",
          label: "草稿",
        },
        {
          value: "1",
          label: "审核中",
        },
        {
          value: "2",
          label: "结案",
        },
        {
          value: "3",
          label: "作废",
        },
      ],
      SearchDialog: false,
      DialogBtnMargin: 0,
      dialogVisible: false,
      selectedRowIndexSave: [],
      bit: true,
    }
  },

  components: { //引入组件后注册组件
    cesTable,
    vGetToolBar,
    SearchForm,
    MianForm
  },
  async mounted() {


    await this.getTableCols()
    await this.getDataList()
    //await this.setData(0);
  },
  methods: {
    //搜索重置
    refresh() {
      this.getDataList();
    }, 
    workbookInitialized: function (workbook, remarkTb) {
      this.spread[remarkTb] = workbook;
    },
    reform() {
      this.Search = {
        // 查询条件
        pageTotal: 0, // 总记录数
        pageSize: 20, // 一页显示的记录数
        page: 1, // /当前页码
        RNO: "001", // 表编号  根据Controller中对应的表编号
        jsWhere: "", // 自定义条件
      };
      this.getDataList();
    },
    //读取列配置
    async getTableCols() {
      this.tableCols = []
      const res = await GetTableColsData({ InterID: "329" });
      this.tableCols = res.data;

      //选添选择
      let row = {
        prop: 'isChecked',
        label: '选择',
        width: 80,
        IsWrite: 1,
        WFStepSN: '-1',
        type: '',
        IsSearch: '0'
        // RowFilterBase. filterButtonVisible
      };

      // let rows = {
      //   prop: 'ID',
      //   label: 'ID',
      //   width: 80,
      //   IsWrite: 1,
      //   WFStepSN: '-1',
      //   type: '',
      //   // visible:false
      // };
      // this.tableCols.unshift(rows);
      this.tableCols.unshift(row);


    },
    async setData(remarkTb) {

      this.spread[0].suspendPaint();
      let sheet = this.spread[0].getActiveSheet();



      sheet.options.protectionOptions.allowSort = false;
      sheet.options.protectionOptions.allowFilter = false;
      //       sheet.options.allowCellOverflow = true;
      sheet.defaults.rowHeight = 23;
      sheet.defaults.colWidth = 100;
      sheet.defaults.colHeaderRowHeight = 23;
      sheet.defaults.rowHeaderColWidth = 60;
      this.spread[remarkTb].options.tabStripVisible = false; //是否显示表单标签
      let colHeader1 = [];
      let colInfos = [];

      sheet.setDataSource(this.tableData);



      this.tableCols.forEach((x, y) => {

        x['name'] = x['prop'];
        x['displayName'] = x['label'];
        x['width'] = parseInt(x.width);
        if (x.prop === 'isChecked') {
          // 选框
          sheet.setCellType(
            0,
            0,
            new HeaderCheckBoxCellType(),
            GCsheets.SheetArea.colHeader,
          );
          x.cellType = new GC.Spread.Sheets.CellTypes.CheckBox();
        } else if (
          x.type === 'comboboxMultiple' ||
          x.type === 'combobox' || x.type === 'Select'
        ) {
          if (x.ValueMember) {

            let newData = []; // 设置列表每行下拉菜单
            x.ColsRowDate.map((item, index) => {

              let row = {
                text: item.label,
                value: item.value,
              };
              newData.push(row);


            });

            let sheet = this.spread[0].getActiveSheet();
            let count = sheet.getRowCount(GC.Spread.Sheets.SheetArea.viewport);
            let style = new GC.Spread.Sheets.Style();
            style.hAlign = GC.Spread.Sheets.HorizontalAlign.center;
            style.vAlign = GC.Spread.Sheets.VerticalAlign.bottom;
            // sheet.setStyle(j, i, style);

            this.tableData.forEach((x, y1) => {
              //居中
              sheet.setStyle(y1, y, style);
              // 获取要绑定下拉菜单的单元格对象
              let cell = sheet.getCell(y1, y);
              // 创建下拉菜单单元格类型，并设置其选项数据
              let comboBox = new GC.Spread.Sheets.CellTypes.ComboBox();
              comboBox.editorValueType(
                GC.Spread.Sheets.CellTypes.EditorValueType.value,
              );
              comboBox.editable(true);
              // 获取下拉菜单的选项数据
              comboBox.items(newData);
              comboBox.itemHeight(24);
              // 将下拉菜单单元格类型绑定到指定的单元格中
              cell.cellType(comboBox);
              // debugger
            })
          }


        } else if (x.type === 'checkbox') {
          let cellType = new GC.Spread.Sheets.CellTypes.CheckBox();
          cellType.caption('');
          cellType.textTrue('');
          cellType.textFalse('');
          cellType.textIndeterminate('');
          cellType.textAlign(
            GC.Spread.Sheets.CellTypes.CheckBoxTextAlign.center,
          );
          cellType.isThreeState(false);
          sheet.getCell(-1, y).cellType(cellType);
        } else if (
          x.type == 'datetime' ||
          x.type === 'varchar' ||
          x.type === 'nvarchar' || x.type === 'Input'
        ) {
          // const cell = sheet.getCell(-1, y);
          // cell.locked(false).foreColor('#2a06ecd9');
          // sheet.getRange(-1, y, 1, 1).locked(false);
          x.formatter = '@';
        }

        const cell = sheet.getCell(-1, y);
        cell.foreColor('black');
        //cell.backColor('white');
        if ((x.IsWrite == '1' && x.WFStepSN.indexOf(this.StepSN) > -1) || x.prop == 'isChecked') {
          cell.locked(false).foreColor('#2a06ecd9');
          //cell.backColor('#45b97c');

        } else if (x.prop != 'isChecked') {

        }

        sheet.options.protectionOptions.allowResizeColumns = true;
        sheet.options.isProtected = true;
        sheet.options.protectionOptions.allowResizeColumns = true;
        sheet.options.protectionOptions.allowInsertRows = true;
        sheet.options.protectionOptions.allowDeleteRows = true;
        sheet.options.protectionOptions.allowSelectLockedCells = true;
        sheet.options.protectionOptions.allowSelectUnlockedCells = true;
        sheet.options.protectionOptions.allowDeleteColumns = true;
        sheet.options.protectionOptions.allowInsertColumns = true;
        sheet.options.protectionOptions.allowDargInsertRows = true;
        sheet.options.protectionOptions.allowDragInsertColumns = true;
        sheet.options.protectionOptions.allowSort = true;
        sheet.options.protectionOptions.allowFilter = true;
        sheet.options.allowUserDragDrop = true;
        //行，start,end
        // if (x.isEdit) {
        //   sheet.getCell(-1, y).locked(false).foreColor("#2a06ecd9");
        // }

        // for (var i = 0; i < sheet.getRowCount(); i++) {

        //   const cell = sheet.getCell(i, y);
        //   cell.foreColor('black');
        // //cell.backColor('white');
        //   if(x.IsWrite == '1'&&x.WFStepSN.indexOf(this.StepSN)>-1)
        //   {
        //     cell.locked(false).foreColor('#2a06ecd9');

        //   }else if(x.prop!='isChecked')
        //   {

        //   }


        // }


      }

      );

      sheet.bindColumns(this.tableCols); //此方法一定要放在setDataSource后面才能正确渲染列名
      sheet.setRowCount(1, GC.Spread.Sheets.SheetArea.colHeader);
      colHeader1.forEach(function (value, index) {
        sheet.setValue(0, index, value, GC.Spread.Sheets.SheetArea.colHeader);


      });


      /////////////////表格事件/////////////
      //绑定表格事件前，需清除之前的绑定事件
      this.spread[remarkTb].unbindAll();
      this.spread[remarkTb].bind(GCsheets.Events.ButtonClicked, (e, args) => {
        const { sheet, row, col } = args;
        const cellType = sheet.getCellType(row, col);
        if (cellType instanceof GCsheets.CellTypes.Button) {
        }
        if (cellType instanceof GCsheets.CellTypes.CheckBox) {

          this.Indexs = row;


        }

        if (cellType instanceof GCsheets.CellTypes.HyperLink) {
        }
      });

      this.spread[0].options.allowContextMenu = true;
      var insertRowsCopyStyle = {
        canUndo: true,
        name: 'insertRowsCopyStyle',
        execute: function (context, options, isUndo) {
          var Commands = GC.Spread.Sheets.Commands;
          if (isUndo) {
            Commands.undoTransaction(context, options);
            return true;
          } else {
            sheet.suspendPaint();
            sheet.addRows(options.activeRow, _this.sheetSelectRows.length);
            //  sheet.setArray(options.activeRow, 0,_this.sheetSelectRows);
            // console.log(_this.sheetSelectRows);

            // console.log(_this.sheetSelectObj.start+_this.sheetSelectRows.length)
            //删除旧行
            if (_this.sheetSelectObj.start > options.activeRow) {
              //说明从下面插入上面
              sheet.copyTo(
                _this.sheetSelectObj.start + _this.sheetSelectRows.length,
                0,
                options.activeRow,
                0,
                _this.sheetSelectRows.length,
                sheet.getColumnCount(),
                GC.Spread.Sheets.CopyToOptions.all,
              );

              //   sheet.setArray(options.activeRow, 0, _this.sheetSelectRows);
              sheet.deleteRows(
                _this.sheetSelectObj.start + _this.sheetSelectRows.length,
                _this.sheetSelectObj.count,
              );
              // sheet.removeRow(_this.sheetSelectObj.start+ _this.sheetSelectRows.length)
            } else {
              //从上面往下面插入
              sheet.copyTo(
                _this.sheetSelectObj.start,
                0,
                options.activeRow,
                0,
                _this.sheetSelectRows.length,
                sheet.getColumnCount(),
                GC.Spread.Sheets.CopyToOptions.all,
              );
              //  sheet.setArray(options.activeRow, 0, _this.sheetSelectRows);
              sheet.deleteRows(
                _this.sheetSelectObj.start,
                _this.sheetSelectObj.count,
              );
            }
            let count = sheet.getRowCount(GC.Spread.Sheets.SheetArea.viewport);

            let lineID = _this.sheetSelectRows[0][lineIDIndex];
            let isFind = false;
            let viewSort = 1;

            for (var i = 0; i < count; i++) {
              if (isFind == false && sheet.getValue(i, lineIDIndex) == lineID) {
                isFind = true;
              }
              if (isFind && sheet.getValue(i, lineIDIndex) != lineID) {
                break;
              }
              if (isFind) {
                sheet.setValue(i, viewSortIndex, viewSort);
                viewSort++;
              }
            }

            // Commands.startTransaction(context, options);

            sheet.suspendPaint();

            // var beforeRowCount = 0;

            //  sheet.suspendPaint();

            // Commands.endTransaction(context, options);
            sheet.resumePaint();

            return true;
          }
        },
      };

      this.spread[remarkTb]
        .commandManager()
        .register('insertRowsCopyStyle', insertRowsCopyStyle);

      function MyContextMenu() { }
      MyContextMenu.prototype = new GC.Spread.Sheets.ContextMenu.ContextMenu(
        this.spread[remarkTb],
      );
      MyContextMenu.prototype.onOpenMenu = function (
        menuData,
        itemsDataForShown,
        hitInfo,
        spread,
      ) {
        itemsDataForShown.forEach(function (item, index) {
          // console.log(item);
          if (item && item.name === 'gc.spread.rowHeaderinsertCutCells') {
            item.command = 'insertRowsCopyStyle';
          }
          //  else if (item && item.name === "gc.spread.cut") {

          //     item.command = "insertRowsCut";
          //   }
        });
      };
      var contextMenu = new MyContextMenu();
      this.spread[remarkTb].contextMenu = contextMenu;


      // 列筛选
      // 参数2 开始列
      // 参数3
      // 参数4 结束列
      let cellrange = new GC.Spread.Sheets.Range(
        -1,
        -1,
        -1,
        this.tableCols.length,
      );
      let hideRowFilter = new GC.Spread.Sheets.Filter.HideRowFilter(cellrange);
      sheet.rowFilter(hideRowFilter);


      sheet.resumePaint();


    }, 
    getSelectionData() {
      let sheet = this.spread.getActiveSheet();
      let newData = sheet.getDataSource();
      this.selectionData[0] = [];
      if (newData.length != 0) {
        newData.forEach((x) => {
          if (x.isChecked) {
            this.selectionData[0].push(x);
          }
        });
      }
    }, //获取当前选中行的值
    selectChanged(newValue, remarkTb) {
      // 在子组件计算属性发生变化时，更新父组件的计算属性
      // debugger
      this.selectionData = newValue;


      // let sheet = this.spread[0].getActiveSheet()
      // let set = sheet.getSelections()[0].row

      // let flag = false
      // this.selectedRowIndexSave.forEach((v, i) => {
      //   if (v == set) {
      //     this.selectedRowIndexSave.splice(i, 1)
      //     flag = true;
      //   }
      // })
      // if (!flag) this.selectedRowIndexSave.push(set)
      // if (this.bit) {
      //   this.selectedRowIndexSave.pop()
      //   this.bit = false
      // }
      // this.selectedRowIndexSave
      // debugger
    },
    async getDataList() {
      const res = await getDataList({ data: JSON.stringify(this.Search) });
      this.tableData = res.data.Table;
      //将data 中的数据放到DataList中
      this.Search.total = res.data.Table1[0].RecordCount;
      this.setData(0);


      // setTimeout(()=>{
      this.cancel()
      // },500)
    }, OpenFindForm() {
      this.getDataList();
      //打开搜索框
      //   this.SearchDialog = true;
      //   //计算外边距
      //   console.log(this.$refs.searchDialog.offsetHeight);
      //   this.DialogBtnMargin = this.$refs.searchDialog.offsetHeight - 40;
    },
    handleOpenClose() {
      this.dialogVisible = false
    }, handlexportData() {
      funDownload("329", JSON.stringify(this.Search));
    }, handleIsfunEdit() {
      this.IsfunEdit = true;
    }, handleIsfunfail() {
      this.Isfunfail = true;
    }, async handeAdd() {
      // 新建
      const result = await UpdateForm({ IsPostBack: false, billID: '' });
      this.FormData = result.data1.Table[0];
      this.dialogType = 'edit'
      this.dialogVisible = true
      this.checkStrictly = true

      this.$nextTick(() => {
        const routes = this.generateRoutes(this.EditObj.routes)
        this.$refs.tree.setCheckedNodes(this.generateArr(routes))
        // set checked state of a node not affects its father and child nodes
        this.checkStrictly = false
        this.getDataList();

      })

    },
    async handleEdit(scope) {
      // 修改


      const result = await UpdateForm({ IsPostBack: false, billID: scope.row.IDXNO });
      this.FormData = result.data1.Table[0];
      this.dialogType = 'edit'
      this.dialogVisible = true
      this.checkStrictly = true

      this.$nextTick(() => {
        const routes = this.generateRoutes(this.EditObj.routes)
        this.$refs.tree.setCheckedNodes(this.generateArr(routes))
        // set checked state of a node not affects its father and child nodes
        this.checkStrictly = false

      })
      this.getDataList();

    },
    async handleSave(scope) {
      // 修改

      const result = await UpdateForm({ IsPostBack: true, billID: this.FormData.IDXNO, HeadDate: JSON.stringify(this.FormData) });
      this.FormData = result.data1.Table[0];

      if (result.code === 20000) {


        this.$notify({
          title: result.msg,
          dangerouslyUseHTMLString: true,
          message: "",
          type: "success",
        });
        this.getDataList();
      } else {
        this.$notify({
          title: result.msg,
          dangerouslyUseHTMLString: true,
          message: "",
          type: "error",
        });
      }


      this.getDataList();

    }, async handleAllSave(scope) {
      // 修改

      const result = await SaveData({ InterID: '329', BodyDate: JSON.stringify(this.tableData) });

      if (result.code === 20000) {


        this.$notify({
          title: result.msg,
          dangerouslyUseHTMLString: true,
          message: "",
          type: "success",
        });
        this.getDataList();
      } else {
        this.$notify({
          title: result.msg,
          dangerouslyUseHTMLString: true,
          message: "",
          type: "error",
        });
      }
      this.getDataList();

    },
    RowsAdd() {
      // this.selectionData
      // let sheet = this.spread[0].getActiveSheet();
      // let count = sheet.getRowCount(GC.Spread.Sheets.SheetArea.viewport);
      // sheet.addRows(count, this.selectionData.length);
      // sheet.copyTo(count, 1, count + 1, 1, this.selectionData.length, this.tableCols.length - 1, GC.Spread.Sheets.CopyToOptions.all);
      // for (let j = 1; j < this.tableCols.length; j++) {
      //   if (this.tableCols[j].ValueMember) continue
      //   sheet.setValue(checkedRows[0] + 1, j, '')
      // }

      let sheet = this.spread[0].getActiveSheet();
      sheet.suspendPaint()
      let count = sheet.getRowCount(GC.Spread.Sheets.SheetArea.viewport);
      //过滤重复的数据
      // let data = this.selectionData.filter(v=>!this.tableData.some(x=>v.ID == x.ID))
      sheet.addRows(count, data.length);
      for (let i = 0; i < data.length; i++) {
        for (let j = 1; j < this.tableCols.length; j++) {
          sheet.setValue(count + i, j, data[i][this.tableCols[j].name]);
        }
      }
      this.tableCols.forEach((x, y) => {
        if (x.ValueMember) {
          let newData = []; // 设置列表每行下拉菜单
          x.ColsRowDate.map((item, index) => {
            let row = {
              text: item.label,
              value: item.value,
            };
            newData.push(row);
          });
          // newData.push(item.value);
          for (let i = count - 1; i < this.tableData.length; i++) {
            // this.tableData.forEach((x, y1) => {
            // 获取要绑定下拉菜单的单元格对象
            let cell = sheet.getCell(i, y);
            // 创建下拉菜单单元格类型，并设置其选项数据
            let comboBox = new GC.Spread.Sheets.CellTypes.ComboBox();
            comboBox.editorValueType(
              GC.Spread.Sheets.CellTypes.EditorValueType.value,
            );
            comboBox.editable(true);
            // 获取下拉菜单的选项数据
            comboBox.items(newData);
            comboBox.itemHeight(24);
            // 将下拉菜单单元格类型绑定到指定的单元格中
            cell.cellType(comboBox);
            // debugger
          }
        }
      })
      sheet.resumePaint()
    },
    FunrRowsAdd() {
      // debugger
      // let row = {
      //   IDXNO: null,
      //   NAME: null,
      //   IDXUP: null,
      //   LB: null,
      //   ID: '',

      // };

      // this.tableData.push(row);

      // this.spread[0].suspendPaint();
      // let sheet = this.spread[0].getActiveSheet();
      // let count = sheet.getRowCount(GC.Spread.Sheets.SheetArea.viewport);
      // sheet.addRows(count + 1, 1);
      // //sheet.suspendPaint()

      // sheet.resumePaint()

      let sheet = this.spread[0].getActiveSheet();
      let count = sheet.getRowCount(GC.Spread.Sheets.SheetArea.viewport);
      sheet.addRows(count , 1);
      sheet.copyTo(count-1, 0, count , 0, 1, this.tableCols.length, GC.Spread.Sheets.CopyToOptions.all);
      for (let j = 0; j < this.tableCols.length; j++) {
        if (this.tableCols[j].ValueMember) continue
        sheet.setValue(count, j, '')
      }


    },
    FunCopyRowsAddOne() {
      let sheet = this.spread[0].getActiveSheet();
      // 获取表格的行数和列数  
      let rowCount = sheet.getRowCount(GC.Spread.Sheets.SheetArea.viewport);
      // 存储勾选复选框的行索引的数组  
      let checkedRows = [];
      // 遍历所有单元格  
      for (let row = 0; row < rowCount; row++) {
        // 获取当前单元格  
        let cell = sheet.getCell(row, 0);
        // 检查单元格是否包含复选框，并且复选框是否被勾选  
        if (cell.value() === true) {
          // 如果复选框被勾选，将行索引添加到数组中  
          checkedRows.push(row);
        }
      }
      // debugger
      if (checkedRows.length != 1) {
        this.$message.warning('请选一条数据')
        return
      }
      // let sheet = this.spread[0].getActiveSheet();
      sheet.addRows(checkedRows[0] + 1, 1);
      sheet.copyTo(checkedRows[0], 0, checkedRows[0] + 1, 0, 1, this.tableCols.length, GC.Spread.Sheets.CopyToOptions.all);
      for (let j = 0; j < this.tableCols.length; j++) {
        if (this.tableCols[j].ValueMember) continue
        sheet.setValue(checkedRows[0] + 1, j, '')
      }
      // debugger
      // sheet.clearSelection();
    },
    FunCopyRowsAdd() {

      let sheet = this.spread[0].getActiveSheet();
      let count = sheet.getRowCount(GC.Spread.Sheets.SheetArea.viewport);
      let checkedRows = [];
      for (let row = 0; row < count; row++) {
        let cell = sheet.getCell(row, 0);
        if (cell.value() === true) {
          checkedRows.push(row);
        }
      }
      // let sheet = this.spread[0].getActiveSheet();
      sheet.addRows(count, checkedRows.length);
      checkedRows.forEach((v, i) => {
        sheet.copyTo(v, 0, count + i, 0, 1, this.tableCols.length, GC.Spread.Sheets.CopyToOptions.all);
        //取消勾选
        sheet.setValue(count + i, 0, '')
      })
      // debugger


      // let sheet = this.spread[0].getActiveSheet();
      // sheet.suspendPaint()
      // let count = sheet.getRowCount(GC.Spread.Sheets.SheetArea.viewport);
      // sheet.addRows(count, this.selectionData.length);
      // for (let i = 0; i < this.selectionData.length; i++) {
      //   for (let j = 1; j < this.tableCols.length; j++) {
      //     sheet.setValue(count + i, j, this.selectionData[i][this.tableCols[j].name]);
      //   }
      // }

      // this.tableCols.forEach((x, y) => {
      //   if (x.ValueMember) {
      //     let newData = []; // 设置列表每行下拉菜单
      //     x.ColsRowDate.map((item, index) => {

      //       let row = {
      //         text: item.label,
      //         value: item.value,
      //       };
      //       newData.push(row);


      //     });

      //     // newData.push(item.value);
      //     for (let i = count - 1; i < this.tableData.length; i++) {
      //       // this.tableData.forEach((x, y1) => {
      //       // 获取要绑定下拉菜单的单元格对象
      //       let cell = sheet.getCell(i, y);
      //       // 创建下拉菜单单元格类型，并设置其选项数据
      //       let comboBox = new GC.Spread.Sheets.CellTypes.ComboBox();
      //       comboBox.editorValueType(
      //         GC.Spread.Sheets.CellTypes.EditorValueType.value,
      //       );
      //       comboBox.editable(true);
      //       // 获取下拉菜单的选项数据
      //       comboBox.items(newData);
      //       comboBox.itemHeight(24);
      //       // 将下拉菜单单元格类型绑定到指定的单元格中
      //       cell.cellType(comboBox);
      //       // debugger
      //     }
      //   }
      // })
      // sheet.resumePaint()

    },
    delData() {
      this.$confirm('删除操作, 是否继续?', '提示', {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
      })
        .then(async () => {

          this.spread[0].suspendPaint();
          let sheet = this.spread[0].getActiveSheet();
          sheet.deleteRows(this.Indexs, 1);
          sheet.resumePaint()
          // debugger
          for (var row of this.selectionData) {



            //

            const result = await DeletForm({
              billID: row.IDXNO,
              IsPostBack: false,
            });

            this.$message({
              type: "success",
              message: result.msg,
            });

          }

          this.getDataList();

        })
        .catch((err) => {
          console.error(err);
        });

    },
    //取消下拉
    cancel() {
      
      let sheet = this.spread[0].getActiveSheet();
      sheet.suspendPaint()
      //居中
      let count = sheet.getRowCount(GC.Spread.Sheets.SheetArea.viewport);
      let style = new GC.Spread.Sheets.Style();
      style.hAlign = GC.Spread.Sheets.HorizontalAlign.center;
      style.vAlign = GC.Spread.Sheets.VerticalAlign.bottom;

      //下拉搜索
      let rowFilter = sheet.rowFilter();
      this.tableCols.forEach((v, i) => {
        if (v.IsSearch != 1) rowFilter.filterButtonVisible(i, false);
        //居中
        if (!v.ValueMember) {
          for (let j = 0; j < count; j++) {
            sheet.setStyle(j, i, style);
          }
        }
      })

      sheet.resumePaint()
      sheet.repaint();

      // 变更列头高度。
      // sheet.setRowHeight(0, 30.0, GC.Spread.Sheets.SheetArea.colHeader);
      // 变更行头宽度
      sheet.setColumnWidth(0, 26.0, GC.Spread.Sheets.SheetArea.rowHeader);




    },


  }
}
</script>

<style lang="scss" scoped>
.app-container {

  // display: flex;
  .ces-main {
    // flex:1;

    // .cesTable {
    // height: 60vh;
    // }
  }

  .searchTop {
    /deep/ .el-input__inner {
      transform: translateY(-3px);
    }

    /deep/ .el-input__suffix {
      transform: translateY(-5px);
    }
  }

  .EditObjs-table {
    margin-top: 30px;
  }

  .permission-tree {
    margin-bottom: 5px;
  }
}

.searchDialog ::v-deep .el-dialog__header {
  background: #409eff;
}

.searchDialog ::v-deep .el-dialog__title {
  color: #fff;
}

.searchDialog ::v-deep .el-dialog__headerbtn .el-dialog__close {
  color: #fff;
}
</style>